package com.xyw.his00.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xyw.his00.mapper.MedicalTechnologyMapper;
import com.xyw.his00.pojo.dbpojo.MedicalTechnology;
import com.xyw.his00.service.Impl.dbImpl.MedicalTechnologyServiceImpl;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/medicalTechnology/")
public class MedicalTechnologyController {
    @Resource
    private MedicalTechnologyServiceImpl medicalTechnologyService;
    @Resource
    private MedicalTechnologyMapper medicalTechnologyMapper;
    //搜索检查项目
    @RequestMapping("selectChecksInfo")
    public List<Map<String,Object>> selectChecksInfo(
          @RequestParam(value="techCode",required = false) String techCode ,
           @RequestParam(value="techName",required = false) String techName
    ){
        //可以1个为空查另一个不为空的内容
        //也可以都查两个表的内容
        QueryWrapper<MedicalTechnology> queryWrapper=new QueryWrapper<>();
        queryWrapper.select("id","tech_code","tech_name","tech_format","tech_type","tech_price","tech_type","price_type","deptment_id");
      if(techCode==null){
           if(techName!=null){
               //实现模糊查询使用like关键字
               queryWrapper.like("tech_name","%"+techName+"%").eq("tech_type","检查");
           }
      }else{
          queryWrapper.like("tech_code","%"+techCode+"%").eq("tech_type","检查");
          if(techName!=null){
              queryWrapper.like("tech_name","%"+techName+"%").eq("tech_type","检查");
          }
      }
           return  medicalTechnologyMapper.selectMaps(queryWrapper);
    }
    //查询支付情况
    @RequestMapping("selectPayInfo")
    public List<HashMap<String,Object>> selectPayInfo(int registerId){
        List<HashMap<String,Object>> hashMaps=new ArrayList<>();
HashMap<String,Object> hashMap=new HashMap<>();
List<MedicalTechnology> m1=medicalTechnologyMapper.selectChecksByState(registerId,"已开立");
List<MedicalTechnology> m2=medicalTechnologyMapper.selectInspectionsByState(registerId,"已开立");
if(m1!=null){
    if(m2!=null){
        hashMap.put("checks",m1);
        hashMap.put("inspections",m2);//put怎么放的
    }
   else {
       hashMap.put("checks",m1);
    }
}else {
    hashMap.put("inspections",m2);
}
        // 设置查询条件
hashMaps.add(hashMap);
        return  hashMaps;
    }

    //查询检验项目列表
    @RequestMapping("selectInspectionsInfo")
    public List<Map<String,Object>> selectInspectionsInfo(
            @RequestParam(value="techCode",required = false) String techCode ,
            @RequestParam(value="techName",required = false) String techName
    ){
        //可以1个为空查另一个不为空的内容
        //也可以都查两个表的内容
        QueryWrapper<MedicalTechnology> queryWrapper=new QueryWrapper<>();
        queryWrapper.select("id","tech_code","tech_name","tech_format","tech_type","tech_price","tech_type","price_type","deptment_id");
        if(techCode==null){
            if(techName!=null){
                //实现模糊查询使用like关键字
                queryWrapper.like("tech_name","%"+techName+"%").eq("tech_type","检验");
            }
        }else{
            queryWrapper.like("tech_code","%"+techCode+"%").eq("tech_type","检验");
            if(techName!=null){
                queryWrapper.like("tech_name","%"+techName+"%").eq("tech_type","检验");
            }
        }
        return  medicalTechnologyMapper.selectMaps(queryWrapper);
    }
    @RequestMapping("selectDisposalsInfo")
    public List<Map<String,Object>> selectDisposalsInfo(
            @RequestParam(value="techCode",required = false) String techCode ,
            @RequestParam(value="techName",required = false) String techName
    ){
        //可以1个为空查另一个不为空的内容
        //也可以都查两个表的内容
        QueryWrapper<MedicalTechnology> queryWrapper=new QueryWrapper<>();
        queryWrapper.select("id","tech_code","tech_name","tech_format","tech_type","tech_price","tech_type","price_type","deptment_id");
        if(techCode==null){
            if(techName!=null){
                //实现模糊查询使用like关键字
                queryWrapper.like("tech_name","%"+techName+"%").eq("tech_type","处置");
            }
        }else{
            queryWrapper.like("tech_code","%"+techCode+"%").eq("tech_type","处置");
            if(techName!=null){
                queryWrapper.like("tech_name","%"+techName+"%").eq("tech_type","处置");
            }
        }
        return  medicalTechnologyMapper.selectMaps(queryWrapper);
    }
}
